from django.db import models


class Commodityclass(models.Model):
    '''商品分类模型类'''
    name = models.CharField(max_length=20, verbose_name='分类名称')

    # image = models.CharField(max_length=200, verbose_name='图片')

    class Meta:
        db_table = 'commodityclass'
        verbose_name = '商品分类'
        verbose_name_plural = verbose_name


class Commodity(models.Model):
    """商品"""
    commodity_class = models.ForeignKey('Commodityclass', verbose_name='商品分类')
    name = models.CharField(max_length=20, verbose_name='商品名称')
    desc_detail1 = models.TextField(default='', verbose_name='商品介绍1')
    desc_detail2 = models.TextField(default='', verbose_name='商品介绍2')
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='价格')
    unit = models.IntegerField(default=0, verbose_name='单位')

    image1 = models.CharField(max_length=200, verbose_name='图片1')
    image2 = models.CharField(max_length=200, verbose_name='图片2')

    class Meta:
        db_table = 'commodity'
        verbose_name = '商品'
        verbose_name_plural = verbose_name

# class SPU(models.Model):
#     """商品SPU"""
#     name = models.CharField(max_length=50, verbose_name='名称')
#     brand = models.ForeignKey(Brand, on_delete=models.PROTECT, verbose_name='品牌')
#     category1 = models.ForeignKey(GoodsCategory, on_delete=models.PROTECT, related_name='cat1_spu', verbose_name='一级类别')
#     category2 = models.ForeignKey(GoodsCategory, on_delete=models.PROTECT, related_name='cat2_spu', verbose_name='二级类别')
#     category3 = models.ForeignKey(GoodsCategory, on_delete=models.PROTECT, related_name='cat3_spu', verbose_name='三级类别')
#     sales = models.IntegerField(default=0, verbose_name='销量')
#     comments = models.IntegerField(default=0, verbose_name='评价数')
#     desc_detail = models.TextField(default='', verbose_name='详细介绍')
#     desc_pack = models.TextField(default='', verbose_name='包装信息')
#     desc_service = models.TextField(default='', verbose_name='售后服务')
#     create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
#     update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
#
#     class Meta:
#         db_table = 'tb_spu'
#         verbose_name = '商品SPU'
#         verbose_name_plural = verbose_name
#
#     def __str__(self):
#         return self.name
#
#
# class SKU(models.Model):
#     """商品SKU"""
#     name = models.CharField(max_length=50, verbose_name='名称')
#     caption = models.CharField(max_length=100, verbose_name='副标题')
#     spu = models.ForeignKey(SPU, on_delete=models.CASCADE, verbose_name='商品')
#     category = models.ForeignKey(GoodsCategory, on_delete=models.PROTECT, verbose_name='从属类别')
#     price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='单价')
#     cost_price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='进价')
#     market_price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='市场价')
#     stock = models.IntegerField(default=0, verbose_name='库存')
#     sales = models.IntegerField(default=0, verbose_name='销量')
#     comments = models.IntegerField(default=0, verbose_name='评价数')
#     is_launched = models.BooleanField(default=True, verbose_name='是否上架销售')
#     default_image = models.CharField(max_length=200, default='', null=True, blank=True, verbose_name='默认图片')
#     create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
#     update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
#
#     class Meta:
#         db_table = 'tb_sku'
#         verbose_name = '商品SKU'
#         verbose_name_plural = verbose_name
#
#     def __str__(self):
#         return '%s: %s' % (self.id, self.name)
#
#
# class SKUImage(models.Model):
#     """SKU图片"""
#     sku = models.ForeignKey(SKU, on_delete=models.CASCADE, verbose_name='sku')
#     image = models.CharField(max_length=200, verbose_name='图片')
#     create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
#     update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
#
#     class Meta:
#         db_table = 'tb_sku_image'
#         verbose_name = 'SKU图片'
#         verbose_name_plural = verbose_name
#
#     def __str__(self):
#         return '%s %s' % (self.sku.name, self.id)
#
#
# class SPUSpecification(models.Model):
#     """商品SPU规格"""
#     spu = models.ForeignKey(SPU, on_delete=models.CASCADE, related_name='specs', verbose_name='商品SPU')
#     name = models.CharField(max_length=20, verbose_name='规格名称')
#     create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
#     update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
#
#     class Meta:
#         db_table = 'tb_spu_specification'
#         verbose_name = '商品SPU规格'
#         verbose_name_plural = verbose_name
#
#     def __str__(self):
#         return '%s: %s' % (self.spu.name, self.name)
#
#
# class SpecificationOption(models.Model):
#     """规格选项"""
#     spec = models.ForeignKey(SPUSpecification, related_name='options', on_delete=models.CASCADE, verbose_name='规格')
#     value = models.CharField(max_length=20, verbose_name='选项值')
#     create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
#     update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
#
#     class Meta:
#         db_table = 'tb_specification_option'
#         verbose_name = '规格选项'
#         verbose_name_plural = verbose_name
#
#     def __str__(self):
#         return '%s - %s' % (self.spec, self.value)
#
#

# class Goods(BaseModel):
#     '''商品SPU模型类'''
#     name = models.CharField(max_length=20, verbose_name='商品SPU名称')
#     # 富文本类型:带有格式的文本
#     detail = HTMLField(blank=True, verbose_name='商品详情')
#
#     class Meta:
#         db_table = 'df_goods'
#         verbose_name = '商品SPU'
#         verbose_name_plural = verbose_name
#
#
#
#
# class IndexTypeGoodsBanner(BaseModel):
#     '''首页分类商品展示模型类'''
#     DISPLAY_TYPE_CHOICES = (
#         (0, "标题"),
#         (1, "图片")
#     )
#
#     type = models.ForeignKey('GoodsType', verbose_name='商品类型')
#     sku = models.ForeignKey('GoodsSKU', verbose_name='商品SKU')
#     display_type = models.SmallIntegerField(default=1, choices=DISPLAY_TYPE_CHOICES, verbose_name='展示类型')
#     index = models.SmallIntegerField(default=0, verbose_name='展示顺序')
#
#     class Meta:
#         db_table = 'df_index_type_goods'
#         verbose_name = "主页分类展示商品"
#         verbose_name_plural = verbose_name
